package com.swind.fast.modules.app.railway.project.service.impl;

import com.swind.fast.common.system.base.service.impl.SwindServiceImpl;
import com.swind.fast.modules.app.railway.project.vo.RailwayProjectSegmentVo;
import com.swind.fast.modules.app.railway.project.entity.RailwayProjectSegment;
import com.swind.fast.modules.app.railway.project.mapper.RailwayProjectSegmentMapper;
import com.swind.fast.modules.app.railway.project.service.IRailwayProjectSegmentService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.swind.fast.modules.system.entity.SysUser;
import com.swind.fast.modules.system.service.ISysUserService;
import com.swind.fast.common.util.oConvertUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.Optional;

/**
 * @Description: 项目
 */
@Slf4j
@Service
public class RailwayProjectSegmentServiceImpl extends SwindServiceImpl<RailwayProjectSegmentMapper, RailwayProjectSegment> implements IRailwayProjectSegmentService {

    @Autowired
    private ISysUserService sysUserService;

    @Override
    public IPage<?> getSegmentListPage(IPage<RailwayProjectSegment> page, QueryWrapper<RailwayProjectSegment> queryWrapper) {

        // IPage<RailwayProjectSegment> pageList = this.page(page, queryWrapper);
        // // log.info("total: {}", pageList.getTotal());
        // if (pageList.getRecords().size() < 1) return pageList;

        // // 获得负责人ID
        // List<String> listIds = pageList.getRecords().stream().map(RailwayProjectSegment::getLeaderId).distinct().collect(Collectors.toList());

        // if (listIds.size() < 1) return pageList;

        // QueryWrapper<SysUser> markQueryWrapper = new QueryWrapper<SysUser>().select("id", "realname", "phone").in("id", listIds);
        // List<SysUser> listUsers = sysUserService.list(markQueryWrapper);
        // log.info("listIds: {}, listUsers: {}", listIds, listUsers);

        // IPage<RailwayProjectSegmentVo> rpageList = pageList.convert(item -> {
        //     RailwayProjectSegmentVo resp = oConvertUtils.entityToModel(item, RailwayProjectSegmentVo.class);

        //     if (listUsers == null) return resp;
        //     // 过滤找出第一个
        //     Optional<SysUser> leaderOpt = listUsers.stream().filter(p -> p.getId().equals(item.getLeaderId())).findFirst();

        //     if (leaderOpt.isPresent()) {
        //         SysUser leader = leaderOpt.get();
        //         resp.setLeaderName(leader.getRealname());
        //         resp.setLeaderPhone(leader.getPhone());
        //     }

        //     return resp;
        // });

        // return rpageList;
        return null;
    }

}
